package protocol.SZ_2021;

public class Handle2021SZ02 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0200(cmd);
            case 0x01:
                return handle0201(cmd);
            case 0x02:
                return handle0202(cmd);
            case 0x03:
                return handle0203(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0203(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:据盲区补传");
        builder.append("\r\n");
        do {
            SZ_2021Utils.handle0200Base(cmd,builder);
            builder.append("\r\n");
            builder.append("\r\n");
        }while (cmd.leftSize() > 0);

        return builder.toString();
    }


    private String handle0200(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:位置信息汇报");
        builder.append("\r\n");
        SZ_2021Utils.handle0200ALL(builder,cmd);
        return builder.toString();
    }

    private String handle0201(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:位置信息查询应答");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("报警标识："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("状态："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("纬度(1/10000分)："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("经度(1/10000分)："+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("速度(1/10KM/H)："+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("方向："+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("时间："+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0202(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:位置跟踪信息汇报");
        builder.append("\r\n");
        SZ_2021Utils.handle0200ALL(builder,cmd);
        return builder.toString();
    }
}
